home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 276-300 / 288 / diskspeed / standardgadgets.c < prev    next >
C/C++ Source or Header  |  1995-03-14  |  11KB  |  343 lines

  1. /*
  2.  *                          DiskSpeed v2.0
  3.  *                                by
  4.  *                           Michael Sinz
  5.  *
  6.  *             Copyright (c) 1989 by MKSoft Development
  7.  *
  8.  *
  9.  * Yes, this is yet another disk speed testing program, but with a few
  10.  * differences.  It was designed to give the most accurate results of the
  11.  * true disk performance in the system.  For this reason many of
  12.  * DiskSpeed's results may look either lower or higher than current disk
  13.  * performance tests.
  14.  *
  15.  * This program was thrown together in a few hours because I needed more
  16.  * accurate and consistent results for disk performance as seen from the
  17.  * application's standpoint.  This program has now served its purpose and
  18.  * I am now giving it to the rest of the Amiga world to play with as long
  19.  * as all of the files remain together in unmodified form.  (That is, the
  20.  * files DiskSpeed, DiskSpeed.info, DiskSpeed.c, DiskSpeedWindow.c,
  21.  * DiskSpeedWindow.h, MakeBoxes.c, MakeBoxes.h, StandardGadgets.c,
  22.  * StandardGadgets.h, RenderInfo.c, RenderInfo.h, DiskSpeed.doc, and
  23.  * MakeFile)
  24.  *
  25.  * Version 2.0 of this program added a few features and cleaned up the
  26.  * user interface.  I hope you like this...
  27.  *
  28.  ******************************************************************************
  29.  *                                          *
  30.  *    Reading legal mush can turn your bain into guacamole!              *
  31.  *                                          *
  32.  *        So here is some of that legal mush:                  *
  33.  *                                          *
  34.  * Permission is hereby granted to distribute this program's source          *
  35.  * executable, and documentation for non-commercial purposes, so long as the  *
  36.  * copyright notices are not removed from the sources, executable or          *
  37.  * documentation.  This program may not be distributed for a profit without   *
  38.  * the express written consent of the author Michael Sinz.              *
  39.  *                                          *
  40.  * This program is not in the public domain.                      *
  41.  *                                          *
  42.  * Fred Fish is expressly granted permission to distribute this program's     *
  43.  * source and executable as part of the "Fred Fish freely redistributable     *
  44.  * Amiga software library."                              *
  45.  *                                          *
  46.  * Permission is expressly granted for this program and it's source to be     *
  47.  * distributed as part of the Amicus Amiga software disks, and the          *
  48.  * First Amiga User Group's Hot Mix disks.                      *
  49.  *                                          *
  50.  ******************************************************************************
  51.  *
  52.  * This file contains the code needed to add standard gadgets to a
  53.  * window.  These are the Close/Front/Back/Drag gadgets...
  54.  *
  55.  * Current limitations:  Gadgets are not rel-size/pos so they only
  56.  * work on fixed sized windows...
  57.  *
  58.  * The drag gadget does not show window Active/Inactive...  :-( :-(
  59.  */
  60.  
  61. #include    <exec/types.h>
  62. #include    <exec/memory.h>
  63. #include    <intuition/intuition.h>
  64.  
  65. #include    <proto/exec.h>
  66. #include    <proto/intuition.h>
  67.  
  68. #include    "RenderInfo.h"
  69. #include    "MakeBoxes.h"
  70. #include    "StandardGadgets.h"
  71.  
  72. static char fontnam[11]="topaz.font";
  73. static struct TextAttr TOPAZ80={fontnam,TOPAZ_EIGHTY,0,0};
  74.  
  75. #define    CLOSE_WIDTH    24
  76. #define    CLOSE_HEIGHT    12
  77.  
  78. static    SHORT    CloseBorderVectors1[8*2]=
  79. {
  80.     4,2,    4,9,    19,9,    19,2,    5,2,    5,9,    18,9,    18,3
  81. };
  82.  
  83. static    SHORT    CloseBorderVectors2[4*2]=
  84. {
  85.     10,5,    13,5,    13,6,    10,6
  86. };
  87.  
  88. struct CloseGadget
  89. {
  90. struct    Gadget    gad;
  91. struct    Window    *win;
  92. struct    Border    Borders[6];
  93.     SHORT    BorderV1[5*2];
  94.     SHORT    BorderV2[5*2];
  95. };
  96.  
  97. struct Gadget *AddCloseGadget(struct Window *Window,struct RenderInfo *ri,SHORT x,SHORT y)
  98. {
  99. register    struct    CloseGadget    *gad;
  100. register        SHORT        loop;
  101.  
  102.     if (gad=AllocMem(sizeof(struct CloseGadget),MEMF_PUBLIC|MEMF_CLEAR))
  103.     {
  104.         gad->win=Window;
  105.  
  106.         gad->gad.LeftEdge=x;
  107.         gad->gad.TopEdge=y;
  108.         gad->gad.Width=CLOSE_WIDTH;
  109.         gad->gad.Height=CLOSE_HEIGHT;
  110.         gad->gad.Flags=GADGHIMAGE;
  111.         gad->gad.Activation=RELVERIFY;
  112.         gad->gad.GadgetType=CLOSE|SYSGADGET;
  113.         gad->gad.GadgetRender=(APTR)&(gad->Borders[0]);
  114.         gad->gad.SelectRender=(APTR)&(gad->Borders[4]);
  115.  
  116.         /* Standard render path... */
  117.         gad->Borders[0].NextBorder=&(gad->Borders[1]);
  118.         gad->Borders[1].NextBorder=&(gad->Borders[2]);
  119.         gad->Borders[2].NextBorder=&(gad->Borders[3]);
  120.  
  121.         /* These point back... */
  122.         gad->Borders[4].NextBorder=&(gad->Borders[5]);
  123.         gad->Borders[5].NextBorder=&(gad->Borders[2]);
  124.  
  125.         /* Border sizes... */
  126.         gad->Borders[0].Count=5;
  127.         gad->Borders[1].Count=5;
  128.         gad->Borders[2].Count=8;
  129.         gad->Borders[3].Count=4;
  130.         gad->Borders[4].Count=5;
  131.         gad->Borders[5].Count=5;
  132.  
  133.         for (loop=0;loop<6;loop++)
  134.         {
  135.             gad->Borders[loop].DrawMode=JAM1;
  136.             gad->Borders[loop].FrontPen=ri->Highlight;
  137.         }
  138.         gad->Borders[1].FrontPen=ri->Shadow;
  139.         gad->Borders[4].FrontPen=ri->Shadow;
  140.  
  141.         gad->Borders[4].XY=gad->Borders[0].XY=gad->BorderV1;
  142.         gad->Borders[5].XY=gad->Borders[1].XY=gad->BorderV2;
  143.         gad->Borders[2].XY=CloseBorderVectors1;
  144.         gad->Borders[3].XY=CloseBorderVectors2;
  145.  
  146.         FillTopLeft_Border(&(gad->Borders[0]),CLOSE_WIDTH,CLOSE_HEIGHT);
  147.         FillBottomRight_Border(&(gad->Borders[1]),CLOSE_WIDTH,CLOSE_HEIGHT);
  148.  
  149.         AddGadget(Window,&(gad->gad),NULL);
  150.         RefreshGList(&(gad->gad),Window,NULL,1L);
  151.     }
  152.     return((struct Gadget *)gad);
  153. }
  154.  
  155. VOID RemCloseGadget(struct Gadget *TheGadget)
  156. {
  157. register    struct    CloseGadget    *gad;
  158.  
  159.     gad=(struct CloseGadget *)TheGadget;
  160.     RemoveGadget(gad->win,&(gad->gad));
  161.     FreeMem(gad,sizeof(struct CloseGadget));
  162. }
  163.  
  164. #define    BACK_WIDTH    26
  165. #define    BACK_HEIGHT    12
  166.  
  167. struct FrontBackGadget
  168. {
  169. struct    Gadget    Back_gad;
  170. struct    Gadget    Front_gad;
  171. struct    Window    *win;
  172. struct    Border    Borders[12];
  173.     SHORT    BorderV1[5*2];
  174.     SHORT    BorderV2[5*2];
  175. };
  176.  
  177. static    SHORT    FrontBackBorderVectors1[10*2]=
  178. {
  179.     6,3,  6,7,  7,7,  7,3,  17,3,  17,2,  4,2,  4,7,  5,7,  5,3
  180. };
  181.  
  182. static    SHORT    FrontBackBorderVectors2[12*2]=
  183. {
  184.     8,4,  21,4,  21,9,  8,9,  8,5,  20,5,  20,8,  9,8,  9,6,  19,6,  19,7,  10,7
  185. };
  186.  
  187. struct Gadget *AddFrontBackGadget(struct Window *Window,struct RenderInfo *ri,SHORT x,SHORT y)
  188. {
  189. register    struct    FrontBackGadget    *gad;
  190. register        SHORT        loop;
  191.  
  192.     if (gad=AllocMem(sizeof(struct FrontBackGadget),MEMF_PUBLIC|MEMF_CLEAR))
  193.     {
  194.         gad->win=Window;
  195.  
  196.         gad->Back_gad.LeftEdge=x;
  197.         gad->Back_gad.TopEdge=y;
  198.         gad->Back_gad.Width=BACK_WIDTH;
  199.         gad->Back_gad.Height=BACK_HEIGHT;
  200.         gad->Back_gad.Flags=GADGHIMAGE;
  201.         gad->Back_gad.Activation=RELVERIFY;
  202.         gad->Back_gad.GadgetType=WDOWNBACK|SYSGADGET;
  203.         gad->Back_gad.GadgetRender=(APTR)&(gad->Borders[0]);
  204.         gad->Back_gad.SelectRender=(APTR)&(gad->Borders[4]);
  205.  
  206.         /* Standard render path... */
  207.         gad->Borders[0].NextBorder=&(gad->Borders[1]);
  208.         gad->Borders[1].NextBorder=&(gad->Borders[2]);
  209.         gad->Borders[2].NextBorder=&(gad->Borders[3]);
  210.  
  211.         /* These point back... */
  212.         gad->Borders[4].NextBorder=&(gad->Borders[5]);
  213.         gad->Borders[5].NextBorder=&(gad->Borders[2]);
  214.  
  215.         gad->Front_gad.LeftEdge=x+BACK_WIDTH;
  216.         gad->Front_gad.TopEdge=y;
  217.         gad->Front_gad.Width=BACK_WIDTH;
  218.         gad->Front_gad.Height=BACK_HEIGHT;
  219.         gad->Front_gad.Flags=GADGHIMAGE;
  220.         gad->Front_gad.Activation=RELVERIFY;
  221.         gad->Front_gad.GadgetType=WUPFRONT|SYSGADGET;
  222.         gad->Front_gad.GadgetRender=(APTR)&(gad->Borders[0+6]);
  223.         gad->Front_gad.SelectRender=(APTR)&(gad->Borders[4+6]);
  224.  
  225.         /* Standard render path... */
  226.         gad->Borders[0+6].NextBorder=&(gad->Borders[1+6]);
  227.         gad->Borders[1+6].NextBorder=&(gad->Borders[2+6]);
  228.         gad->Borders[2+6].NextBorder=&(gad->Borders[3+6]);
  229.  
  230.         /* These point back... */
  231.         gad->Borders[4+6].NextBorder=&(gad->Borders[5+6]);
  232.         gad->Borders[5+6].NextBorder=&(gad->Borders[2+6]);
  233.  
  234.         /* Border sizes... */
  235.         for (loop=0;loop<12;loop++) gad->Borders[loop].Count=5;
  236.         gad->Borders[2+6].Count=gad->Borders[2].Count=10;
  237.         gad->Borders[3+6].Count=gad->Borders[3].Count=12;
  238.  
  239.         /* Pen colours... */
  240.         for (loop=0;loop<12;loop++)
  241.         {
  242.             gad->Borders[loop].DrawMode=JAM1;
  243.             gad->Borders[loop].FrontPen=ri->Highlight;
  244.         }
  245.         gad->Borders[1].FrontPen=ri->Shadow;
  246.         gad->Borders[2].FrontPen=ri->Shadow;
  247.         gad->Borders[4].FrontPen=ri->Shadow;
  248.         gad->Borders[1+6].FrontPen=ri->Shadow;
  249.         gad->Borders[3+6].FrontPen=ri->Shadow;
  250.         gad->Borders[4+6].FrontPen=ri->Shadow;
  251.  
  252.         gad->Borders[4+6].XY=gad->Borders[0+6].XY=gad->Borders[4].XY=gad->Borders[0].XY=gad->BorderV1;
  253.         gad->Borders[5+6].XY=gad->Borders[1+6].XY=gad->Borders[5].XY=gad->Borders[1].XY=gad->BorderV2;
  254.         gad->Borders[2+6].XY=gad->Borders[2].XY=FrontBackBorderVectors1;
  255.         gad->Borders[3+6].XY=gad->Borders[3].XY=FrontBackBorderVectors2;
  256.         FillTopLeft_Border(&(gad->Borders[0]),BACK_WIDTH,BACK_HEIGHT);
  257.         FillBottomRight_Border(&(gad->Borders[1]),BACK_WIDTH,BACK_HEIGHT);
  258.  
  259.         AddGadget(Window,&(gad->Back_gad),NULL);
  260.         RefreshGList(&(gad->Back_gad),Window,NULL,1L);
  261.  
  262.         AddGadget(Window,&(gad->Front_gad),NULL);
  263.         RefreshGList(&(gad->Front_gad),Window,NULL,1L);
  264.     }
  265.     return((struct Gadget *)gad);
  266. }
  267.  
  268. VOID RemFrontBackGadget(struct Gadget *TheGadget)
  269. {
  270. register    struct    FrontBackGadget    *gad;
  271.  
  272.     gad=(struct FrontBackGadget *)TheGadget;
  273.     RemoveGadget(gad->win,&(gad->Back_gad));
  274.     RemoveGadget(gad->win,&(gad->Front_gad));
  275.     FreeMem(gad,sizeof(struct FrontBackGadget));
  276. }
  277.  
  278. #define    DRAG_HEIGHT    12
  279.  
  280. struct DragGadget
  281. {
  282. struct    Gadget        gad;
  283. struct    Window        *win;
  284. struct    IntuiText    iText;
  285. struct    Border        Borders[2];
  286.     SHORT        BorderV1[5*2];
  287.     SHORT        BorderV2[5*2];
  288. };
  289.  
  290. struct Gadget *AddDragGadget(struct Window *Window,struct RenderInfo *ri,char *text,SHORT x,SHORT y,SHORT xSize)
  291. {
  292. register    struct    DragGadget    *gad;
  293.  
  294.     if (gad=AllocMem(sizeof(struct DragGadget),MEMF_PUBLIC|MEMF_CLEAR))
  295.     {
  296.         gad->win=Window;
  297.  
  298.         gad->gad.LeftEdge=x;
  299.         gad->gad.TopEdge=y;
  300.         gad->gad.Width=xSize;
  301.         gad->gad.Height=CLOSE_HEIGHT;
  302.         gad->gad.Flags=GADGHNONE;
  303.         gad->gad.GadgetType=WDRAGGING|SYSGADGET;
  304.         gad->gad.GadgetRender=(APTR)&(gad->Borders[0]);
  305.         gad->gad.GadgetText=&(gad->iText);
  306.  
  307.         gad->iText.FrontPen=ri->TextPen;
  308.         gad->iText.DrawMode=JAM1;
  309.         gad->iText.TopEdge=2;
  310.         gad->iText.ITextFont=&TOPAZ80;
  311.         gad->iText.IText=text;
  312.         gad->iText.LeftEdge=(xSize-IntuiTextLength(&(gad->iText))) >> 1;
  313.  
  314.         /* Standard render path... */
  315.         gad->Borders[0].NextBorder=&(gad->Borders[1]);
  316.  
  317.         /* Border sizes... */
  318.         gad->Borders[0].Count=gad->Borders[1].Count=5;
  319.  
  320.         gad->Borders[0].DrawMode=gad->Borders[1].DrawMode=JAM1;
  321.         gad->Borders[0].FrontPen=ri->Shadow;
  322.         gad->Borders[1].FrontPen=ri->Highlight;
  323.  
  324.         gad->Borders[0].XY=gad->BorderV1;
  325.         gad->Borders[1].XY=gad->BorderV2;
  326.         FillTopLeft_Border(&(gad->Borders[0]),xSize,DRAG_HEIGHT);
  327.         FillBottomRight_Border(&(gad->Borders[1]),xSize,DRAG_HEIGHT);
  328.  
  329.         AddGadget(Window,&(gad->gad),NULL);
  330.         RefreshGList(&(gad->gad),Window,NULL,1L);
  331.     }
  332.     return((struct Gadget *)gad);
  333. }
  334.  
  335. VOID RemDragGadget(struct Gadget *TheGadget)
  336. {
  337. register    struct    DragGadget    *gad;
  338.  
  339.     gad=(struct DragGadget *)TheGadget;
  340.     RemoveGadget(gad->win,&(gad->gad));
  341.     FreeMem(gad,sizeof(struct DragGadget));
  342. }
  343.